﻿using DMS.Models;
using DMS.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace DMS.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/
        private readonly BUS.Bus _bus = new BUS.Bus();
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult CategoryMenu()
        {
            var model = new List<CategoryObject>();
            model = _bus.GetCatregoryTree(); //_bus.ReturnCategoryTree().Where(c=>c.CategoryActive==true).ToList();
            return View(model);
        }

        public ActionResult Banner(int? position)
        {
            if(!position.HasValue)
            {
                position = 0;
            }
            var model = new BannerObject();

            model = _bus.Banner_Select_FE(position.GetValueOrDefault());
            return View(model);

        }

        public ActionResult Documents()
        {
            int categoryId = 0;
            if(Request.Params["catId"]!=null)
            {
                categoryId = Convert.ToInt32(Request.Params["catId"]);
            }
            var model = new List<DocumentObject>();
            model = _bus.Document_Select_by_CatId(categoryId);
            return View(model);
        }

        public ActionResult Read(int? docId)
        {
            var model = new DocumentObject();
            ViewBag.Filename = string.Empty;
            ViewBag.Mode = false;
            model = _bus.Document_Select_by_Id(docId.GetValueOrDefault());

            //if (model != null)
            //{
            //    String doc_name = model.DocumentLink;
            //    doc_name = "1_Premiers pas.pdf";
            //    if (String.IsNullOrWhiteSpace(doc_name))
            //    {
            //        throw new HttpException(403, "Document name is invalid");
            //    }
            //    if (FileRepository.IsPresent(doc_name) == false)
            //    {
            //        throw new HttpException(404, "Document is absent");
            //    }
            //    String raw_mode = "1";
            //    Boolean HTML_mode;
            //    if (raw_mode == "1")
            //    {
            //        HTML_mode = false;
            //    }
            //    else if (raw_mode == "2")
            //    {
            //        HTML_mode = true;
            //    }
            //    else
            //    {
            //        throw new HttpException(403, "'Mode' parameter is invalid");
            //    }
            //    ViewBag.Filename = model.DocumentLink;
            //    ViewBag.Mode = HTML_mode;
            //}
            return View(model);
        }

        [HttpPost]
        public JsonResult Post(string hotspotmac)
        {
            return Json(new { hotspotmac = hotspotmac });
        }

        //[HttpPost]
        //public ActionResult (string hotspotmac)
        //{
        //    var obj = new BannerObject();
        //    return Json(new {hotspotmac=hotspotmac});
        //}
    }
}
